package com.xmbandu.app.activity;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;

import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.xmbandu.app.R;
import com.xmbandu.app.base.BaseActivity;
import com.xmbandu.app.home.fragment.SimpleCardFragment;

import java.util.ArrayList;

/**
 * @author wmq
 * @date 2019-05-24
 * @description
 */
public class BookListActivity extends BaseActivity {
    private ArrayList<SimpleCardFragment> mFragments = new ArrayList<>();
   // private String[] mTitles = {"教育", "故事"};
    private ImageView mBack;
    private ImageView search;
    //private ViewPager mViewPager;
    //private SegmentTabLayout mTabLayout;
    private WebView mWebView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_booklist;
    }

    @Override
    public void initViews() {
        mBack = (ImageView) findViewById(R.id.back);
        search = (ImageView) findViewById(R.id.search);
        //mViewPager = (ViewPager) findViewById(R.id.viewpager);
       // mTabLayout = (SegmentTabLayout) findViewById(R.id.tl_2);
        mWebView=(WebView)findViewById(R.id.webView);
    }

    @Override
    public void initListener() {
        setOnClick(mBack);
        setOnClick(search);
    }

    @Override
    public void initData() {
        //initTab();
        mWebView.loadUrl("https://server.everobo.com/web/wxH5/bookSeek.html?from=groupmessage&isappinstalled=0");
    }

    @Override
    public void processClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.search:
                Intent intent = new Intent(this, SearchActiviy.class);
                startActivity(intent);
                break;
        }
    }

    /*private void initTab() {
        for (String title : mTitles) {
            mFragments.add(SimpleCardFragment.getInstance(title));
        }
        initFragmentView();
    }

    // 初始化书单fragment
    private void initFragmentView() {
        mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        mTabLayout.setTabData(mTitles);
        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                mViewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {
            }
        });

        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mTabLayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        // 设置书单fragment 默认选中
        mViewPager.setCurrentItem(0);
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public SimpleCardFragment getItem(int position) {
            return mFragments.get(position);
        }
    }*/

    public static void start(Context context) {
        Intent intent = new Intent(context, BookListActivity.class);
        context.startActivity(intent);
    }
}
